package com.ccc.scala.base7_collection

object Collection15_Sliding {

  def main(args: Array[String]): Unit = {
    // 滑动（窗口）

    val list = List(1, 2, 3, 4, 5, 6, 7, 8)

    val iterator = list.sliding(3)
    while (iterator.hasNext) {
      val ints = iterator.next()
      println(ints)
      /*
      List(1, 2, 3)
      List(2, 3, 4)
      List(3, 4, 5)
      List(4, 5, 6)
      List(5, 6, 7)
      List(6, 7, 8)
       */
    }
    val iterator1 = list.sliding(3, 2)
    while (iterator1.hasNext) {
      val ints = iterator1.next()
      println(ints)
      /*
      List(1, 2, 3)
      List(3, 4, 5)
      List(5, 6, 7)
      List(7, 8)
       */
    }

  }

}
